﻿package cn.antscript.airCMS.display.component.btnbase 
{
	import cn.antscript.airCMS.display.component.Tips;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.GlowFilter;
	
	/**
	 * ...
	 * @author antscript
	 */
	public class AbstractIco extends Sprite
	{
		protected var _bitmap:Bitmap;
		protected var _label:String;
		
		public function AbstractIco(bitmapData:BitmapData,label:String="",container:DisplayObjectContainer=null,xPos:int=0,yPos:int=0,isAutoDel:Boolean=true) 
		{
			if (container != null) {
				container.addChild(this);
			}
			this.x = xPos;
			this.y = yPos;
			
			_label = label;
			
			_bitmap = new Bitmap();
			_bitmap.bitmapData=bitmapData
			addChild(_bitmap);
			
			
			this.mouseChildren = false;
			this.buttonMode = true;
			
			addEventListener(MouseEvent.ROLL_OVER, onOver);
			addEventListener(MouseEvent.ROLL_OUT, onOut);
			
			if (isAutoDel) {
				addEventListener(Event.REMOVED_FROM_STAGE, onRemove);
			}
			
		}
		
		private function onRemove(e:Event):void 
		{
			removeEventListener(Event.REMOVED_FROM_STAGE, onRemove);
			
			removeEventListener(MouseEvent.ROLL_OVER, onOver);
			removeEventListener(MouseEvent.ROLL_OUT, onOut);
			
			_bitmap.bitmapData = null;
			
		}
		
		protected function onOver(e:MouseEvent):void 
		{
			Tips.getInstance().show(this, _label);
			this.filters = [new GlowFilter(0xffffff)];
			
		}		
		
		protected function onOut(e:MouseEvent):void 
		{
			Tips.getInstance().hide();
			this.filters = [];
		}
		
	}

}